package com.yanqu.road.server.cmd.cricket;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cricket.CricketProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.cricketcourt.CrossCricketCourtMgr;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

@Cmd(code = Protocol.C_CRICKET_COURT_UPDATE_USER_INFO, desc = "同步游戏服的数据到跨服")
public class CrossCricketCourtUpdateUserInfoCmd extends CrossCommand {

    private int type;

    private long userId;

    private List<CricketProto.CricketMatchDataTemp> cricketDefenseList;

    private int courtBadgeId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CricketProto.CricketCourtUpdateUserInfoReqMsg reqMsg = CricketProto.CricketCourtUpdateUserInfoReqMsg.parseFrom(packet.getBytes());
        userId = packet.getPlayerId();
        type = reqMsg.getType();
        cricketDefenseList = reqMsg.getCricketDefenseList();
        if (reqMsg.hasCourtBadgeId()) {
            courtBadgeId = reqMsg.getCourtBadgeId();
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        if (type == 1) {
            // 更新防守阵容
            CrossCricketCourtMgr.updateUserCricketDefense(serverId, userId, cricketDefenseList);
        } else if (type == 2) {
            // 更新勋章信息
            CrossCricketCourtMgr.updateUserCricketBadge(serverId, userId, courtBadgeId);
        }
    }

    @Override
    public void sendData() {

    }
}
